package io.qytc.jboot.support.auth;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import io.qytc.jboot.utils.LicenseUtils;

/**
 * 根据url的权限拦截器，具有url权限的角色才允许访问
 * @author Rlax
 *
 */
public class LicensesInterceptor implements Interceptor {

    @Override
    public void intercept(Invocation ai) {

        boolean isLicensesValid = false;
        try {
            isLicensesValid = LicenseUtils.isLicenseValid();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (!isLicensesValid){
            ai.getController().redirect("/licenses");
            //ai.getController().renderJson(RestResult.buildError("Licenses过期"));
        }else {
            ai.invoke();
        }
    }

}
